//
// Created by xie on 2021/5/25.
//
#include <iostream>
#include <utility>
#include <tuple>

using namespace std;
int pair_tuple_test(){
    pair<int,int> a;
    a.first = 1;
    a.second = 2;
    auto b = pair<int,int>(std::move(a));
    cout<<a.first<<" "<<a.second<<endl;

    auto c = make_pair(1.4,2.5);
    cout<<c.first<<' '<<c.second<<endl;
    cout<<typeid(std::tuple_element<0, pair<int,int>>::type).name();

    cout<<'-----'<<endl;
    tuple<int, int ,int ,float> t1{1,2,3,44.5};
    cout<<(tuple_size<decltype(t1)>::value)<<endl; // get size of tuple
    cout<<get<3>(t1)<<endl; // get specified element of tuple

    auto made = make_tuple(1,2,4,5,6,7,"this is test");
    cout<< typeid(decltype(made)).name()<<endl;
    // you have to declare size const here to use in get<size>
    const size_t size = tuple_size<decltype(made)>::value;
    cout<<"last value of tuple is: "<<get<size-1>(made)<<endl;
    // get returns reference
    get<0>(made) *= 3;

    string s1 = "str1";
    tuple<int, string&> fire(1, s1);
    {
        string s2 = "str2";
        get<1>(fire) = s2;
    }
    // why we still get str2 here?
    cout<<get<1>(fire)<<endl;

}
